package com.ttg.utils.connection;

//~--- non-JDK imports --------------------------------------------------------


//~--- JDK imports ------------------------------------------------------------

//~--- classes ----------------------------------------------------------------

import com.ttg.utils.Assert;

import java.io.File;

/**
 * Class HttpUploadFile
 * Description
 * Create 2016-02-25 01:04:47 
 * @author Ardy    
 */
public class HttpUploadFile {

    /** 
     * Field parameterName
     * Description 
     */
    private final String parameterName;

    /** 
     * Field fileName
     * Description 
     */
    private final String fileName;

    /** 
     * Field file
     * Description 
     */
    private File file;

    /** 
     * Field content
     * Description 
     */
    private byte[] content;

    /**
     * Constructs HttpUploadFile
     * Description
     *
     * @param parameterName 类型：String
     * @param fileName 类型：String
     * @param file 类型：File
     * @param content 类型：byte[]
     */
    public HttpUploadFile(String parameterName, String fileName, File file, byte[] content) {
        Assert.hasText(parameterName);
        this.parameterName = parameterName;
        Assert.hasText(fileName);
        this.fileName = fileName;

        if (( file != null ) && ( content != null )) {
            throw new IllegalArgumentException("File文件和byte[]内容只能存在一个!");
        } else if (( file == null ) && ( content == null )) {
            throw new IllegalArgumentException("File文件和byte[]内容都为null,至少要存在一个!");
        } else if (( content != null ) || ( ( file != null ) && ( !file.exists() ||!file.isDirectory() ) )) {
            this.file    = file;
            this.content = content;
        } else {
            throw new IllegalArgumentException("file[" + file.getAbsolutePath() + "]必须是一个不存在的文件,不能为null,且不能是一个已存在的目录");
        }
    }

    /**
     * Method getParameterName 
     * Description 说明：
     *
     * @return 返回值说明：
     */
    public String getParameterName() {
        return this.parameterName;
    }

    /**
     * Method getFileName 
     * Description 说明：
     *
     * @return 返回值说明：
     */
    public String getFileName() {
        return this.fileName;
    }

    /**
     * Method getFile 
     * Description 说明：
     *
     * @return 返回值说明：
     */
    public File getFile() {
        return this.file;
    }

    /**
     * Method getContent 
     * Description 说明：
     *
     * @return 返回值说明：
     */
    public byte[] getContent() {
        return this.content;
    }

    /**
     * Method setFile 
     * Description 说明：
     *
     * @param file 说明：
     */
    public void setFile(File file) {
        this.file = file;
    }

    /**
     * Method setContent 
     * Description 说明：
     *
     * @param content 说明：
     */
    public void setContent(byte[] content) {
        this.content = content;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
